package main

func main() {

}

func nextGreaterElement(nums1 []int, nums2 []int) []int {
	n2 := len(nums2)
	m := make(map[int]int)
	stack := make([]int, n2)
	stackTop := -1
	for i := n2 - 1; i >= 0; i-- {
		if stackTop == -1 {
			stackTop++
			stack[stackTop] = nums2[i]
			continue
		}
		if stack[stackTop] > nums2[i] {
			m[nums2[i]] = stack[stackTop]
			stackTop++
			stack[stackTop] = nums2[i]
			continue
		}
		stackTop--
		i++
	}
	for i := range nums1 {
		if m[nums1[i]] > 0 {
			nums1[i] = m[nums1[i]]
			continue
		}
		nums1[i] = -1
	}
	return nums1
}
